package com.scc.generate.word.frame;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * @ClassName: FrameInitUtil
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author javascc@126.com
 * @date 2023年3月31日 下午1:51:03
 * 
 */
public class PanelInitUtil {
	public static final String DEFAULT_DBURL = "jdbc:mysql://127.0.0.1:3306/[db_name]?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
	public static final String[] DEFAULT_DRIVEROPTIONS = { "com.mysql.cj.jdbc.Driver" };
	public static final String DEFAULT_DBNAME = "root";
	public static final String DEFAULT_DBPWD = "123456";
	public static final String DEFAULT_FILEPATH = "/Users/[user]/Desktop/words/";
	public static final String DEFAULT_NAME = "数据库文档";
	public static final String DEFAULT_VERSION = "V1.0.0";
	public static final String[] DEFAULT_ENGINEFILETYPES = { "WORD文件", "HTML文件", "Markdown文件" };
	public static final String[] DEFAULT_ISOPENDS = { "打开", "不打开" };
	public static final JComboBox DRIVERCOMBOBOX = PanelInitUtil.initSelect(140, 20, 350, 25,
			PanelInitUtil.DEFAULT_DRIVEROPTIONS);
	public static final JTextField URLTEXTFIELD = PanelInitUtil.initJTextField(140, 50, 350, 25,
			PanelInitUtil.DEFAULT_DBURL);
	public static final JTextField UANMETEXTFIELD = PanelInitUtil.initJTextField(140, 80, 350, 25,
			PanelInitUtil.DEFAULT_DBNAME);
	public static final JTextField PASSWORDTEXTFIELD = PanelInitUtil.initJTextField(140, 110, 350, 25,
			PanelInitUtil.DEFAULT_DBPWD);
	public static final JTextField FILEPATHTEXTFIELD = PanelInitUtil.initJTextField(140, 140, 350, 25,
			PanelInitUtil.DEFAULT_FILEPATH);
	public static final JTextField IGNORETABLENAMETEXTFIELD = PanelInitUtil.initJTextField(140, 170, 350, 25, "");
	public static final JTextField IGNOREPREFIXTEXTFIELD = PanelInitUtil.initJTextField(140, 210, 350, 25, "");
	public static final JTextField IGNORESUFFIXTEXTFIELD = PanelInitUtil.initJTextField(140, 250, 350, 25, "");
	public static final JTextField NAMETEXTFIELD = PanelInitUtil.initJTextField(140, 290, 350, 25,
			PanelInitUtil.DEFAULT_NAME);
	public static final JTextField VERSIONTEXTFIELD = PanelInitUtil.initJTextField(140, 330, 350, 25,
			PanelInitUtil.DEFAULT_VERSION);
	public static final JComboBox ENGINEFILETYPECOMBOBOX = PanelInitUtil.initSelect(140, 370, 350, 25,
			PanelInitUtil.DEFAULT_ENGINEFILETYPES);
	public static final JComboBox ISOPENDSCOMBOBOX = PanelInitUtil.initSelect(140, 410, 350, 25,
			PanelInitUtil.DEFAULT_ISOPENDS);
	public static final JButton LOGINBUTTON = PanelInitUtil.initJButton("生成", 140, 450, 350, 25);
	public static final JTextArea INFOJTEXTAREA = PanelInitUtil.initJTextArea();
	public static final JScrollPane JSP = PanelInitUtil.initJScrollPane(INFOJTEXTAREA, 10, 490, 350, 100);

	public static JLabel initJLabel(String name, int x, int y, int width, int height) {
		JLabel jLabel = new JLabel(name);
		jLabel.setBounds(x, y, width, height);
		return jLabel;
	}

	public static JComboBox initSelect(int x, int y, int width, int height, String... options) {
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(options));
		comboBox.setBounds(x, y, width, height);
		return comboBox;
	}

	public static JTextField initJTextField(int x, int y, int width, int height, String defaultValue) {
		JTextField jTextField = new JTextField(20);
		jTextField.setBounds(x, y, width, height);
		jTextField.setText(defaultValue);
		return jTextField;
	}

	public static JButton initJButton(String name, int x, int y, int width, int height) {
		JButton jButton = new JButton(name);
		jButton.setBounds(x, y, width, height);
		return jButton;
	}

	public static JScrollPane initJScrollPane(JTextArea jTextArea, int x, int y, int width, int height) {
		JScrollPane jsp = new JScrollPane(jTextArea);
		jsp.setBounds(x, y, width, height);
		jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		return jsp;
	}

	public static JTextArea initJTextArea() {
		JTextArea jTextArea = new JTextArea();
		jTextArea.setLineWrap(true);
		return jTextArea;
	}

	/**
	 * @Title: initPanel
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @author chengcai.shang@cmgplex.com
	 * @date 2023年3月31日 下午2:30:45
	 * @param panel
	 */
	public static void initPanel(JPanel panel) {
		// 驱动类
		panel.add(PanelInitUtil.initJLabel("驱动类", 10, 20, 80, 25));
		panel.add(DRIVERCOMBOBOX);
		// URL
		panel.add(PanelInitUtil.initJLabel("URL:", 10, 50, 80, 25));
		panel.add(URLTEXTFIELD);
		// 用户名
		panel.add(PanelInitUtil.initJLabel("用户名:", 10, 80, 80, 25));
		panel.add(UANMETEXTFIELD);
		// 密码
		panel.add(PanelInitUtil.initJLabel("密码:", 10, 110, 80, 25));
		panel.add(PASSWORDTEXTFIELD);
		// 文件位置
		panel.add(PanelInitUtil.initJLabel("文件位置:", 10, 140, 80, 25));
		panel.add(FILEPATHTEXTFIELD);
		// 忽略表名
		panel.add(PanelInitUtil.initJLabel("忽略表名(逗号分隔):", 10, 170, 120, 25));
		panel.add(IGNORETABLENAMETEXTFIELD);
		// 忽略前缀
		panel.add(PanelInitUtil.initJLabel("忽略前缀(逗号分隔):", 10, 210, 120, 25));
		panel.add(IGNOREPREFIXTEXTFIELD);
		// 忽略后缀
		panel.add(PanelInitUtil.initJLabel("忽略后缀(逗号分隔):", 10, 250, 120, 25));
		panel.add(IGNORESUFFIXTEXTFIELD);
		// 名称
		panel.add(PanelInitUtil.initJLabel("文档名称:", 10, 290, 120, 25));
		panel.add(NAMETEXTFIELD);
		// 版本号
		panel.add(PanelInitUtil.initJLabel("文档版本号:", 10, 330, 120, 25));
		panel.add(VERSIONTEXTFIELD);
		// 生成文档类型
		panel.add(PanelInitUtil.initJLabel("文档类型:", 10, 370, 120, 25));
		panel.add(ENGINEFILETYPECOMBOBOX);
		// 是否生成后打开
		panel.add(PanelInitUtil.initJLabel("生成后打开:", 10, 410, 120, 25));
		panel.add(ISOPENDSCOMBOBOX);
		// 按钮
		panel.add(LOGINBUTTON);
		// 信息输出
		panel.add(JSP);

	}
}
